package com.example.bbs.kafka.producer;

import com.alibaba.fastjson.JSON;
import com.example.bbs.domain.entity.Comment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class CommentProducer {
    @Autowired
    private KafkaTemplate kafkaTemplate;

    public void send(String topic, Comment comment) {
        kafkaTemplate.send(topic, JSON.toJSONString(comment));
        log.info("评论Id为[" + comment.getCommentId() + "]," + "主题为:[" + topic + "]的消息发送成功!");
    }
}
